<template>
  <div class="common-layout">
    <el-container>
      <el-aside width="300px" class="aside">
        <div class="title">
          学生成绩管理系统
        </div>
        <el-menu
            default-active="/index"
            :background-color="'#303642'"
            :text-color="'#e4e4e4'"
            :active-text-color="'#ffffff'"
            router
        >
          <el-menu-item index="/index">
            <el-icon>
              <icon-menu/>
            </el-icon>
            <span>首页</span>
          </el-menu-item>
          <el-sub-menu index="student">
            <template #title>
              <el-icon>
                <location/>
              </el-icon>
              <span>学生管理</span>
            </template>
            <el-menu-item index="/student/list">学生列表</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header class="common-header">
          <el-dropdown>
            <el-icon color="#ffffff">
              <setting/>
            </el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="handleLogout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <div class="name">
            欢迎，{{ username }}
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>

</template>
<script setup lang="ts">
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from '@element-plus/icons-vue'
import {useStore} from "vuex";
import {computed, onMounted} from "vue";
import {useRouter} from "vue-router";

const store = useStore()
const router = useRouter()
const username = computed(() => store.getters["auth/getUserName"])
const handleLogout = async () => {
  await store.dispatch("auth/logout")
  await router.push("/login")
}
onMounted(() => {
  console.log(router.getRoutes())
})
</script>
<style scoped lang="scss">
.common-layout {
  width: 100vw;
  height: 100vh;

  .aside {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: #303642;

    .title {
      color: #ffffff;
      height: 10vh;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 36px;
      border-right: 1px solid #e4e4e4;
    }

    :deep(.el-menu--vertical) {
      height: 90vh;
    }
  }

  .common-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    background-color: #3894b3;
    color: #ffffff;

    .name {
      padding: 0 8px;
    }
  }
}

</style>